package com.atguigu.controller;


import com.alibaba.fastjson.JSONObject;
import com.atguigu.entity.BaseCategory1;
import com.atguigu.entity.BaseCategory2;
import com.atguigu.entity.BaseCategory3;
import com.atguigu.entity.PlatformPropertyKey;
import com.atguigu.result.RetVal;
import com.atguigu.service.BaseCategory1Service;
import com.atguigu.service.BaseCategory2Service;
import com.atguigu.service.BaseCategory3Service;
import com.atguigu.service.BaseCategoryViewService;
import com.atguigu.service.impl.BaseCategory1ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 一级分类表 前端控制器
 * </p>
 *
 * @author zhangqiang
 * @since 2021-08-21
 */
@RestController
@RequestMapping("/product")
public class CategoryController {
    @Autowired
    BaseCategory1Service baseCategory1Service;

    @Autowired
    BaseCategory2Service baseCategory2Service;

    @Autowired
    BaseCategory3Service baseCategory3Service;

    @Autowired
    BaseCategoryViewService baseCategoryViewService;

    @GetMapping("getCategory1")
    public RetVal getCategory1(){
        //查询所有一级分类
        List<BaseCategory1> list = baseCategory1Service.list(null);
        return  RetVal.ok(list);
    }

    @GetMapping("getCategory2/{category1Id}")
    public RetVal getCategory2(@PathVariable Long category1Id){
        //查询所有一级分类
        QueryWrapper<BaseCategory2> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("category1_id",category1Id);
        List<BaseCategory2> list = baseCategory2Service.list(queryWrapper);
        return  RetVal.ok(list);
    }

    @GetMapping("getCategory3/{category2Id}")
    public RetVal getCategory3(@PathVariable Long category2Id){
        //查询所有一级分类
        QueryWrapper<BaseCategory3> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("category2_id",category2Id);
        List<BaseCategory3> list = baseCategory3Service.list(queryWrapper);
        return  RetVal.ok(list);
    }

    @GetMapping("getIndexCategoryInfo")
    public RetVal getIndexCategoryInfo(){
        List<JSONObject> categoryInfo =baseCategoryViewService.getIndexCategoryInfo();
        return RetVal.ok(categoryInfo);
    }


}

